#+_+ coding:utf-8 +_+
import json
import config
import request

__author__ = 'cz'


class Depth(object):
    ask = []
    bid = []
    def __init__(self):
        pass

class DepthRequest(request.Request):
    def __init__(self):
        super(DepthRequest, self).__init__()
        self.set_host(config.svr_host)
        self.set_path(config.svr_path + "/future_depth.do")
        self.set_headers({"Content-type": "application/x-www-form-urlencoded"})
        param = dict()
        param["symbol"] = "btc_usd"
        param["contract_type"] = "this_week"
        param["app_key"] = config.app_key
        param["size"] = 5
        param["merge"] = 1
        self.set_parameters(param)


def query():
    req = DepthRequest()
    rsp = req.do_request()
    body = rsp.body()
    body_json = json.loads(body)
    if body_json.has_key("error_code"):
        return None
    depth = Depth()
    depth.ask = body_json["asks"]
    depth.bid = body_json["bids"]
    return depth